<div class="login-box">
  <div class="login-box-content">
    {if $user->isLoggedIn()}
      <span>login</span>
      <a class="log" href="{plink User:detail userId=>$user->getId()}">profil</a>
      <a class="reg" n:href="logout!" class="ajax">odhlásit</a>
    {else}
      <span>login</span>
      <a class="log" href="#" id="showLoginForm">přihlásit</a> 
      <a class="reg" href="#" id="showRegisterForm">registrovat</a>
    {/if}
  </div>  
  
  <div class="login-form" id="loginForm" style="display: none">
    {form loginForm}
      <ul class="errors" n:if="$form->hasErrors()">
          <li n:foreach="$form->errors as $error">{$error}</li>
      </ul>
      <input type="text" style="display: none">
      <input type="password" style="display: none">
      <div class="form form-row">
        {label nickname class=>array(form, form-label)/}
        {input nickname class=>array(form, form-text-input)}
      </div>
      <div class="form form-row">
        {label password class=>array(form, form-label)/}
        {input password class=>array(form, form-text-input)}
      </div>
      <div class="button-row center">
        {input loginSubmit class=>array(button, standard)}
      </div>
    {/form}
    </div>
    
    <div class="register-form" id="registerForm" style="display: none">
    {form registerForm}
      <div id="regError" class="errors">
      </div>
      
      <div class="form form-row">
        {label login class=>array(form, form-label) /}
        {input login class=>array(form, form-text-input)}
      </div>
      
      <div class="form form-row">
        {label password class=>array(form, form-label) /}
        {input password class=>array(form, form-text-input)}
      </div>
      
      <div class="form form-row">
        {label password_again class=>array(form, form-label) /}
        {input password_again class=>array(form, form-text-input)}
      </div>
      
      <div class="form form-row">
        {label email class=>array(form, form-label)/}
        {input email class=>array(form, form-text-input)}
      </div>
      
      <div class="form form-row">
        {input rules class=>array(form, form-checkbox-input)} Souhlasím s <strong><a href="#">podmínkami</a></strong>
      </div>
      
      <div class="button-row center">
        {input send class=>array(button, standard)}
      </div>
    {/form}    
    </div>
</div>
    
  <script>
  $(document).ready(function(){
    $('#showLoginForm').click(function(e){
        e.preventDefault();
        $('#registerForm').fadeOut();
        if($('#loginForm').css('display') === 'none'){
          $('#loginForm').fadeIn();
        }else{
          $('#loginForm').fadeOut();
        }
    });
    $('#showRegisterForm').click(function(e){
        e.preventDefault();
        $('#loginForm').fadeOut();
        if($('#registerForm').css('display') === 'none'){
          $('#registerForm').fadeIn();
        }else{
          $('#registerForm').fadeOut();
        }
    });
    
    $('#registerForm form').submit(function(event){
      event.preventDefault();
      $('#regError').text("");
      
      $.ajax({
        data: $(this).serialize(),
        method: 'post',
        dataType: 'json',
        url: $(this).attr('action'),
//        dataType: 'json',
        success: function(response){
          if(response.status === "error"){
            $('#regError').text(response.data);
          }else if(response.status === "ok"){
            $('#registerForm').fadeOut();
            $('#reg-text').text(response.data);
            $('#reg-flash').fadeIn();
          }
        },
        
        error: function(error){
  
        }
      });
    });
  });
  </script>

